Skip to content

fix: honor per-type ShallowCopyForSameType override (#938)#975

Closed
leno23 wants to merge 1 commit into
MapsterMapper:developmentfrom
leno23:fix/per-type-shallow-copy-938-dev
Closed

fix: honor per-type ShallowCopyForSameType override (#938)#975
leno23 wants to merge 1 commit into
MapsterMapper:developmentfrom
leno23:fix/per-type-shallow-copy-938-dev

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 25, 2026

Summary

  • Fixes Does Mapster has a way to explicitly map the same object while false ShallowCopyForSameType? #938 by resolving ShallowCopyForSameType from merged per-type settings when adapting same-type members, instead of always using the parent mapping's settings.
  • A parent self-mapping with ShallowCopyForSameType(false) no longer suppresses global shallow-copy behavior for nested implicit same-type members.
  • Explicit per-type ShallowCopyForSameType(false) overrides still force deep copy for self-mappings, including MapToTarget restore scenarios with ctor-initialized nested properties.

Root cause

CreateAdaptExpression checked arg.Settings.ShallowCopyForSameType from the enclosing mapping context. When a parent type opted into deep copy, nested same-type members incorrectly inherited that setting even when their own merged settings/default should remain shallow.

Test plan

  • WhenPerTypeShallowCopyOverride.GlobalShallowCopy_WithPerTypeDeepCopy_ShouldRestoreViaMapToTarget
  • WhenPerTypeShallowCopyOverride.ParentDeepCopyOverride_ShouldNotDisableImplicitNestedShallowCopyForSameType
  • Existing WhenConfiguringMapping shallow-copy tests pass

Resolve ShallowCopyForSameType from merged settings for same-type member
adaptation so a parent mapping's deep-copy override does not suppress
global shallow-copy behavior on nested same-type members, while explicit
per-type false overrides still force deep copy for self-mappings.

Co-authored-by: Cursor <cursoragent@cursor.com>
@leno23
Copy link
Copy Markdown
Author

leno23 commented May 26, 2026

Closing as duplicate of #974 — both target #938; keeping #974 which uses merged settings directly for same-type shallow copy and includes the issue reference in tests.

@leno23 leno23 closed this May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant